symboliccolor: Allow props == NULL when resolving
authorBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 10:58:11 +0000 (12:58 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 20:17:58 +0000 (22:17 +0200)
If props == NULL in gtk_symbolic_color_resolve(), fail sanely for named
colors. The docs used to say it was not allowed to pass NULL for named
color, but that had problems:
1) You do not know if a color was created that way. This is especially
   hard for generic users (like language bindings).
2) It wasn't even true. Colors using other symbolic colors would also
   fail when trying to resolve their named colors, but the docs didn't
   say so.
And because I want to use the function to resolve static colors early
where possible, I changed things.

gtk/gtksymboliccolor.c

index a359fe1fea18b6f91183ad71dd0bb4e2a311915f..d99aa136d3691417d0a8c95e3cc4d894c2869fb8 100644 (file)
@@ -474,8 +474,9 @@ _shade_color (GdkRGBA *color,
  * if @color can't be resolved, it is due to it being defined on
  * top of a named color that doesn't exist in @props.
  *
- * @props must be non-%NULL if @color was created using
- * gtk_symbolic_color_named_new(), but can be omitted in other cases.
+ * When @props is %NULL, resolving of named colors will fail, so if
+ * your @color is or references such a color, this function will
+ * return %FALSE.
  *
  * Returns: %TRUE if the color has been resolved
  *
@@ -488,6 +489,7 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
 {
   g_return_val_if_fail (color != NULL, FALSE);
   g_return_val_if_fail (resolved_color != NULL, FALSE);
+  g_return_val_if_fail (props == NULL || GTK_IS_STYLE_PROPERTIES (props), FALSE);
 
   switch (color->type)
     {
@@ -498,7 +500,8 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
       {
         GtkSymbolicColor *named_color;
 
-        g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
+        if (props == NULL)
+          return FALSE;
 
         named_color = gtk_style_properties_lookup_color (props, color->name);